<?
	  	  include("/inc/header.html") {}
    ?>
<div class="col-lg-4">
	<div class="panel" style="height: 500px; overflow: auto;">
		<div class="panel-body">
			<!--  <div><a href="javascript:qingling();"><h4>根目录</h4></a></div> -->
			<div style="margin-top: -10px;margin-left: 10px;">
				<button style="height: 35px;width: 55px;" type="button"
					class="btn btn-blue btn-xs" >
					<h5>根目录</h5>
				</button>
			</div>
			<ul id="tree" class="ztree" style="width:300px"; overflow:auto;"></ul>
		</div>
	</div>
</div>

<script>
	function getQueryString(name) {
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
		var r = window.location.search.substr(1).match(reg);
		if (r != null)
			return unescape(r[2]);
		return null;
	}
	var winName = getQueryString("winName");
	/* var id = getQueryString("id"); */
	var classid;
	var classname;
	$(function() {
		initTree();
	});
	function initTree() {

		$.ajax({
			type : "post",
			data : {
				/* "id":id */
			},
			url : "cmsNavbarCategoryZtree.do",
			dataType : "json",
			beforeSend : function(XMLHttpRequest) {
			},
			success : drawTree,
		});
	}
	function drawTree(data) {
		if(data.msg == "OK"){
			var setting = {
				view : {
					dblClickExpand : false,
				},
				data : {
					simpleData : {
						enable : true,
					}
				},
				check : {
					enable : false
				},
				callback : {
					onClick : onClick
				},
			};
			var zNodes = eval(data.data);
			$.fn.zTree.init($("#tree"), setting, zNodes).expandAll(true);
			zTree = $.fn.zTree.getZTreeObj("tree");
			zTree.expandNode(zTree.getNodes()[0], true);
		}else{
			alert("请求失败")
		}

	}

	function onClick(e, treeId, treeNode) {
		classid = treeNode.id;
		classname = treeNode.name;
		classValue = treeNode.value;
	}

	function save() {
		if (classid == null) {
			var index = parent.layer.getFrameIndex(window.name);
			/* if(pageId ==1 ){ */
				window.parent.window[winName].$("#dataTypeId").val("0");
				window.parent.window[winName].$("#categoryText").val("根节点");
			/* }else{
				window.parent.window[winName].$("#columnId").val("0");
				window.parent.window[winName].$("#columnName").val("根节点");
				window.parent.window[winName].demo(1,"news",0);
			} */
			parent.layer.close(index);
		} else {
			var index = parent.layer.getFrameIndex(window.name);
		/* 	if(pageId ==1 ){ */
				window.parent.window[winName].$("#dataTypeId").val(classValue);
				window.parent.window[winName].$("#categoryText").val(classname);
			/* }else{
				window.parent.window[winName].$("#columnId").val(classid);
				window.parent.window[winName].$("#columnName").val(classname);
				window.parent.window[winName].demo(1,"news",classid);
			} */
			parent.layer.close(index);
		}
	}

	/* function qingling() {
		var index = parent.layer.getFrameIndex(window.name);
		window.parent.window[winName].$("#parentClassid").val("0");
		window.parent.window[winName].$("#parentclassname").val("根节点");
		parent.layer.close(index);
	} */
</script>